import { Controller, Get, Body, Patch, Param, Post } from '@nestjs/common'
import { UserService } from './user.service'
import { UpdateUserDto } from './dto/update-user.dto'
import { AuthJWT } from 'src/decorator/auth.decorator'
import { GetUserInfo } from 'src/decorator/getUserInfo.decotator'
import { User } from '@prisma/client'
import { UpdatePassword } from './dto/update-password.dto'

@Controller('user')
export class UserController {
   constructor(private readonly userService: UserService) {}

   @AuthJWT()
   @Get()
   findOne(@GetUserInfo() user: User) {
      return this.userService.findOne(+user.id)
   }

   @AuthJWT()
   @Post('/upUserInfo')
   upUserInfo(@Body() updateUserDto: UpdateUserDto, @GetUserInfo() user: User) {
      return this.userService.upUserInfo(updateUserDto, +user.id)
   }

   @AuthJWT()
   @Get('/commont')
   findUserCommontAll(@GetUserInfo() user: User) {
      return this.userService.findUserCommontList(+user.id)
   }

   @AuthJWT()
   @Patch()
   upPassword(@Body() updatePassword: UpdatePassword, @GetUserInfo() user: User) {
      return this.userService.upPassword(updatePassword, +user.id)
   }

   // 添加经纬度
   @AuthJWT()
   @Post('/location')
   upLocation(@Body() updateLocation: { latitude: number; longitude: number }, @GetUserInfo() user: User) {
      return this.userService.upLocation(+user.id, updateLocation)
   }
}
